<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" style="margin-top: 6px;" size="small" label-width="90px">
      <el-form-item label="父模块名" prop="parentModuleName">
        <el-input v-model="form.parentModuleName" style="width: 245px;"/>
      </el-form-item>
      <el-form-item label="模块名" prop="moduleName">
        <el-input v-model="form.moduleName" style="width: 245px;"/>
      </el-form-item>
      <el-form-item label="组名" prop="groupName">
        <el-input v-model="form.groupName" style="width: 245px;"/>
      </el-form-item>
      <el-form-item label="子模块名" prop="childModuleName">
        <el-input v-model="form.childModuleName" style="width: 245px;"/>
      </el-form-item>
      <el-form-item label="版本" prop="childModuleName">
        <el-input v-model="form.versionName" style="width: 245px;"/>
      </el-form-item>
      <el-form-item label="">
        <el-button :loading="loading" size="medium" type="primary" @click="doSubmit">生成</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
    import {moduleFileGenerator} from "@/api/code-tools"
    import {downloadFileFunction} from "@/api/downloadFile"

    export default {
        data() {
            return {
                url: '',
                // 新窗口的引用
                newWin: null,
                loading: false,
                form: {
                    parentModuleName: 'aidam_scaffold',
                    moduleName: '-base',
                    groupName: 'com.aici',
                    childModuleName: '-base-api,-base-impl',
                    versionName: ''
                },
                rules: {
                    moduleName: [
                        {required: true, message: '模块名不能为空', trigger: 'blur'}
                    ],
                    groupName: [
                        {required: true, message: '组名不能为空', trigger: 'blur'}
                    ],
                    childModuleName: [
                        {required: true, message: '子模块名不能为空', trigger: 'blur'}
                    ]
                }
            }
        },
        methods: {
            doSubmit() {
                this.loading = true;
                moduleFileGenerator({
                        parentModuleName: this.form.parentModuleName,
                        moduleName: this.form.moduleName,
                        groupName: this.form.groupName,
                        childModuleNameList: this.form.childModuleName,
                        versionName: this.form.versionName
                    }
                ).then(res => {
                    this.loading = false;
                    console.log(res);
                    downloadFileFunction(res, this.form.moduleName + `.zip`);
                }).catch(err => {
                    this.loading = false;
                    console.log(err);
                })
            }
        }
    }
</script>
